<template>
	<view>
		<view class="top_card" v-if="typeShow == 1">

			<view class="title">
				{{$t("user.update-current-pay-pwd")}}
			</view>
			<u-message-input :maxlength="6" @change="change" @finish="finish" :focus="true" :value="oldPwd">
			</u-message-input>
		</view>


		<view class="top_card" v-else>
			<view class="title">
				{{$t("user.update-new-pay-pwd")}}
			</view>

			<u-message-input :maxlength="6" @change="change1" @finish="finishNew" :focus="true" :value="newPwd">
			</u-message-input>

		</view>
	</view>
</template>
<script>
	import {
		recordPwd,
		updatePwd
	} from '@/api/new.js';
	export default {

		data() {
			return {
				typeShow: 1,
				newPwd: '',
				oldPwd: '',
				type: 'password',
				passwordIcon: true,
				border: true,
			}
		},
		methods: {
			onLoad() {
				uni.setNavigationBarTitle({
					title: this.$t("user.update-pay-pwd")
				})
			},
			change(e) {
				this.oldPwd = e
				console.log('内容改变，当前值为：' + e);
			},
			finish(e) {
				let that = this
				this.oldPwd = e
				// this.typeShow = 2
				// this.show = false
				let data = {
					oldPwd: e
				}
				recordPwd(data).then(res => {
					console.log(res, 'res');
					this.typeShow = 2
					this.show = false
				}).catch(res => {
					console.log(res,'resssss');
						that.$util.Tips({
							title: this.$t('user.update-pay-pwd-error')
						});
						
				});
						console.log('输入结束，当前值为：' + e);
					},
					change1(e) {
						this.newPwd = e
						console.log('内容改变，当前值为：' + e);
					},
					finishNew(e) {
						let that = this
						this.newPwd = e
						
						// this.show = false
						let data = {
							newPwd: e
						}
						updatePwd(data).then(res => {
							console.log(res, 'resnewPwd');
							that.$util.Tips({
								title: this.$t('user.update-pay-pwd-go')
							});
							setTimeout(()=>{
								uni.navigateBack()
							},1500)
						}).catch(res => {
						that.$util.Tips({
							title: res
						});
						
				});
						console.log('输入结束，当前值为：' + e);
					},
				}
			}
</script>
<style lang="scss">
	.top_card {
		padding: 45px 10px;

		.title {
			display: flex;
			justify-content: center;
			padding: 10px 0;
			font-weight: bold;
			font-size: 18px
		}
	}
</style>